<%@page import="org.jeecgframework.web.util.StaticValue"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>联系表</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
<script type="text/javascript">
function checkTpHeaderUnique(){
	var type = $("#type").val();
	var belongOrg = $("#belongOrg").val();//机构
	var position = $("#position").val();//职位
	var conBusiness = $("input[name='conBusiness']:checked").val();//业务
	var state = $("#state").val();//状态
	var flag = true;
	if(type === '<%=StaticValue.DIC_CONTACT_TYPE_TP_CONTACT%>' &&
			position === '<%=StaticValue.DIC_CONTACT_POSITION_TP_SERVER_BUSINESSR%>' && 
			conBusiness != undefined && conBusiness.indexOf('<%=StaticValue.DIC_BUS_SCOPE_INSPECTION%>') >= 0 && 
					state === '<%=StaticValue.DIC_ENGINEER_STATE_ONJOB%>'){
		$.ajax({
			url : "zyContactsController.do?checkTpIpHeaderUnique",
			data : {
				"belongOrg" : belongOrg,
				"type" : "update",
				"id" : '${zyContactsPage.id }'
			},
			cache : false,
			dataType : 'json',
			async : false,
			type : 'POST',
			success : function(data){
				if(!data.success){
					tip(data.msg);
				}
				flag = data.success;
			}
		});
	}
	var belongCinema = $("#belongCinema").val();
	if(flag){//检查 影院 巡检 联系人 唯一性
		if(type === '<%=StaticValue.DIC_CONTACT_TYPE_CINEMA_CONTACT%>' &&
				position === '<%=StaticValue.DIC_CONTACT_POSITION_C_MANAGER%>' && 
				 conBusiness != undefined && conBusiness.indexOf('<%=StaticValue.DIC_BUS_SCOPE_INSPECTION%>') >= 0 && 
						state === '<%=StaticValue.DIC_ENGINEER_STATE_ONJOB%>'){
			$.ajax({
				url : "zyContactsController.do?checkCmIpHeaderUnique",
				data : {
					"belongCinema" : belongCinema,
					"id" : '${zyContactsPage.id }'
					},
				cache : false,
				dataType : 'json',
				async : false,
				type : 'POST',
				success : function(data){
					if(!data.success){
						tip(data.msg);
					}
					flag = data.success;
				}
			});
		}
	}
	var cellphone1 = $("#cellphone1").val();
	var cellphone2 = $("#cellphone2").val();
	if(flag){//通过第一个验证 才可以进行第二个验证
		var name = $("#name").val();
		if(name !== '' && cellphone1 !== ''){
			$.ajax({
				url : "zyContactsController.do?checkCtUnique",
				data : {
					"id" : '${zyContactsPage.id }',
					"type" : "update",
					"name" : name,
					"cellphone1" : cellphone1
					},
				cache : false,
				dataType : 'json',
				async : false,
				type : 'POST',
				success : function(data){
					if(!data.success){
						tip(data.msg);
					}
					flag = data.success;
				}
			});
		}
	}
	if(flag){
		var baseId = $("#sysUserId").val();
		if(baseId !== ''){
			$.ajax({
				url : "zyContactsController.do?checkLinkSysUserUnique",
				data : {
					"baseId" : baseId,
					"id" : '${zyContactsPage.id }'
					},
				cache : false,
				dataType : 'json',
				async : false,
				type : 'POST',
				success : function(data){
					if(!data.success){
						tip(data.msg);
					}
					flag = data.success;
				}
			});
		}
	}
	if(flag){
		if(cellphone1 !== '' && cellphone2 !== '' && cellphone1 == cellphone2){
			tip("手机1和手机2不能相同");
			flag = false;
		}
	}
	return flag;
}
</script>
 </head>
 <body>
  <t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" action="zyContactsController.do?doUpdate" tiptype="4" beforeSubmit="checkTpHeaderUnique">
		<input id="id" name="id" type="hidden" value="${zyContactsPage.id }">
		<input name="isDelete" type="hidden" value="${zyContactsPage.isDelete }">
		<input name="wxBindId" type="hidden" value="${wxBindId }">
		<table cellpadding="0" cellspacing="1" class="formtable" >
					<tr>
						<td align="right">
							<label class="Validform_label">
								系统用户:
							</label>
						</td>
						<td class="value">
							<input name="tsBaseUser.id" type="hidden" id="sysUserId" value='${zyContactsPage.tsBaseUser.id}'>
			                <input name="realName" class="inputxt" id="realName" value='${zyContactsPage.tsBaseUser.realName}' readonly="readonly" />
			                <t:choose hiddenName="sysUserId" hiddenid="id" url="zyContactsController.do?zySysUsers" name="sysUserList"
			                          icon="icon-search" title="系统用户列表" textname="realName" isclear="true"></t:choose>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">系统用户</label>
						</td>
						<td align="right">
							<label class="Validform_label">
								类型:
							</label>
						</td>
						<td class="value">
					     	 <%-- <input id="type" name="type" type="text" style="width: 150px" class="inputxt" value='${zyContactsPage.type}'> --%>
<%--					     	 <t:dictSelect field="" type="" defaultVal="" dictField="<%=StaticValue.DIC_CONTACT_TYPE %>"/>--%>
							<input type="hidden" name="type" value="${zyContactsPage.type}" />
					     	 <select id="type" onchange="changeType()" disabled="disabled">   
						        <option id='cinema_contact' value="<%=StaticValue.DIC_CONTACT_TYPE_CINEMA_CONTACT %>">影院联系人</option>   
						        <option id='tp_contact' value="<%=StaticValue.DIC_CONTACT_TYPE_TP_CONTACT %>">第三方联系人</option>
					      	</select>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">联系人类型</label>
						</td>
					</tr>
					<tr>
						<td align="right">
							<label class="Validform_label">
								所属机构或影院:
							</label>
						</td>
						<td class="value" id="cinema">
							<input name="belongCinema.id"  type="hidden" id="belongCinema" value='${zyContactsPage.belongCinema.id}'>
			                <input name="cinemaName" class="inputxt" id="cinemaName" value='<c:if test="${not empty zyContactsPage}">${zyContactsPage.belongCinema.name}</c:if><c:if test="${not empty cinemaName}">${cinemaName}</c:if>' readonly="readonly" />
			                <t:choose hiddenName="belongCinema" hiddenid="id" url="zyCinemaController.do?zyChooseCmOfContact" name="cinemaList"
			                          icon="icon-search" title="影院列表" textname="name" inputTextname="cinemaName"  isclear="true"></t:choose>
						</td>
						<td class="value" id="org" style="display: none;">
								<input name="belongOrg.id" type="hidden" id="belongOrg" value='${zyContactsPage.belongOrg.id}'>
				                <input name="shortname" class="inputxt" id="shortname" value='${zyContactsPage.belongOrg.shortname}' readonly="readonly" style="width:260px;"/>
				                <t:choose hiddenName="belongOrg" hiddenid="id" url="zyContactsController.do?zyOrgs" name="orgList"
				                          icon="icon-search" title="机构列表" textname="shortname" isclear="true"></t:choose>
						</td>
						<td align="right">
							<label class="Validform_label">
								名字:
							</label>
						</td>
						<td class="value">
						   <input id="name" name="name" type="text" style="width: 150px" class="inputxt" datatype="*" nullmsg="请填写名字" value='${zyContactsPage.name}'/>
							<!-- <span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">名字</label> -->
						</td>
					</tr>
					<tr>
						<td align="right">
							<label class="Validform_label">
								手机1:
							</label>
						</td>
						<td class="value">
						  	<input id="cellphone1" name="cellphone1" type="text" style="width: 150px" class="inputxt"  datatype="cPhone" value='${zyContactsPage.cellphone1}' />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">手机1</label>
						</td>
						<td align="right">
							<label class="Validform_label">
								手机2:
							</label>
						</td>
						<td class="value">
						   	<input id="cellphone2" name="cellphone2" type="text" style="width: 150px" class="inputxt" value='${zyContactsPage.cellphone2}' />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">手机2</label>
						</td>
					</tr>
					<tr>
						<td align="right">
							<label class="Validform_label">
								固话:
							</label>
						</td>
						<td class="value">
							<input id="telephone" name="telephone" type="text" style="width: 150px" class="inputxt" value='${zyContactsPage.telephone}' />    
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">固话</label>
						</td>
						<td align="right">
							<label class="Validform_label">
								性别:
							</label>
						</td>
						<td class="value">
							<t:dictSelect field="gender" type="select" typeGroupCode="<%=StaticValue.DIC_SEX %>" defaultVal="${zyContactsPage.gender}" />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">性别</label>
						</td>
					</tr>
					<tr>
						<td align="right">
							<label class="Validform_label">
								传真:
							</label>
						</td>
						<td class="value">
							<input id="fax" name="fax" type="text" style="width: 150px" class="inputxt" value='${zyContactsPage.fax}' />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">传真</label>
						</td>
						<td align="right">
							<label class="Validform_label">
								email:
							</label>
						</td>
						<td class="value">
						    <input id="email" name="email" type="text" style="width: 150px" class="inputxt" value='${zyContactsPage.email}' />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">email</label>
						</td>
					</tr>
					<tr>
						<td align="right">
							<label class="Validform_label">
								职位:
							</label>
						</td>
						<td class="value">
							<t:dictSelect field="position" id="position" type="select" typeGroupCode="<%=StaticValue.DIC_CONTACT_POSITION %>" defaultVal="${zyContactsPage.position}" hasPleaseSelect="false"/>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">职位</label>
						</td>
						<td align="right">
							<label class="Validform_label">
								来源:
							</label>
						</td>
						<td class="value">
						    <input id="source" name="source" type="text" style="width: 150px" class="inputxt" value='${zyContactsPage.source}' />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">来源</label>
						</td>
					</tr>
					<tr>
                        <td align="right">
                            <label class="Validform_label">
                                是否钻石:
                            </label>
                        </td>
                        <td class="value">
                            <t:dictSelect field="authentication" id="authentication" type="select" typeGroupCode="trueOfFlaseNum" defaultVal="${zyContactsPage.authentication}"></t:dictSelect>
                        </td>

						<td align="right">
							<label class="Validform_label">
								状态:
							</label>
						</td>
						<td class="value">
							<t:dictSelect field="state" id="state" type="select" typeGroupCode="<%=StaticValue.DIC_ENGINEER_STATE %>" defaultVal="${zyContactsPage.state}" />
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">状态</label>
						</td>
					</tr>
                    <tr>
                        <td align="right">
                            <label class="Validform_label">
                                联系业务:
                            </label>
                        </td>
                        <td class="value" colspan="3">
                            <t:dictSelect field="conBusiness" type="checkbox" typeGroupCode="<%=StaticValue.DIC_LINK_BUSINESS %>" defaultVal="${zyContactsPage.conBusiness}" />
                            <span class="Validform_checktip"></span>
                            <label class="Validform_label" style="display: none;">联系业务</label>
                        </td>
                    </tr>
					
			</table>
		</t:formvalid>
 </body>
  <script src = "webpage/com/zybk/zy_contacts/zyContacts.js"></script>
  <script type="text/javascript">
  
  function editAppvalStatus(){
	  var wxAuthType = $('#wxAuthType').val();
	  if(wxAuthType == 1){
		  $("#cinemaName").attr({"datatype":"*","nullmsg":"请选择所属影院"});
	  }else if(wxAuthType == 2){
		  $("#cinemaName").removeAttr("datatype nullmsg");
	  }
  }
function changeType() {
	var type= $("#type").val();
	if(type === '<%=StaticValue.DIC_CONTACT_TYPE_TP_CONTACT%>'){
		$("#org").show();
		$("#cinema").hide();  
		$("#shortname").attr({"datatype":"*","nullmsg":"请选择所属机构"});
		$("#cinemaName").removeAttr("datatype nullmsg");
	}else if(type === '<%=StaticValue.DIC_CONTACT_TYPE_CINEMA_CONTACT%>'){
		$("#cinema").show();
		$("#org").hide();   
		$("#cinemaName").attr({"datatype":"*","nullmsg":"请选择所属影院"});
		$("#shortname").removeAttr("datatype nullmsg");
	}else if(type === '<%=StaticValue.DIC_CONTACT_TYPE_WX_CONTACT%>'){
		$("#cinema").show();
		$("#org").hide();
		$("#cinemaName").attr({"datatype":"*","nullmsg":"请选择所属影院"});
		$("#shortname").removeAttr("datatype nullmsg");
	}
}
  	
  	$(document).ready(function() { 
  		var type = '${zyContactsPage.type}';
    	if(type === '<%=StaticValue.DIC_CONTACT_TYPE_TP_CONTACT%>'){
    		$("#tp_contact").attr("selected",true);
    		$("#org").show();
    		$("#cinema").hide();
    	}else if(type === '<%=StaticValue.DIC_CONTACT_TYPE_CINEMA_CONTACT%>'){
    	  	$("#cinema_contact").attr("selected",true);
    	  	$("#cinema").show();
    	  	$("#org").hide();
    	}else if(type === '<%=StaticValue.DIC_CONTACT_TYPE_WX_CONTACT%>'){
    		$("#wx_contact").attr("selected",true);
    	  	$("#cinema").show();
    	  	$("#org").hide();
    		$("#cinemaName").attr({"datatype":"*","nullmsg":"请选择所属影院"});
    		$("#shortname").removeAttr("datatype nullmsg");
		}
  	}); 
  </script>			